<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>银行系统安全登录</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Arial', 'Microsoft YaHei', sans-serif;
        }

         body {
            background-image: url("R-C.jpg");
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .login-container {
            width: 100%;
            max-width: 450px;
            background-color: #ffffff;
            border-radius: 12px;
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.25);
            overflow: hidden;
            animation: fadeIn 0.8s ease-out;
        }

        .login-header {
            background-color: #1a3a6c;
            color: white;
            padding: 25px 30px;
            text-align: center;
            position: relative;
        }

        .login-tabs {
            display: flex;
            background-color: rgba(255, 255, 255, 0.15);
            border-radius: 50px;
            padding: 3px;
            margin: 15px auto 10px;
            max-width: 300px;
        }

        .tab {
            flex: 1;
            padding: 8px 0;
            text-align: center;
            border-radius: 50px;
            cursor: pointer;
            font-size: 15px;
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .tab.active {
            background-color: white;
            color: #1a3a6c;
            font-weight: 600;
        }

        .login-header h2 {
            font-size: 24px;
            font-weight: 600;
            margin-bottom: 5px;
        }

        .login-header p {
            font-size: 14px;
            opacity: 0.9;
            margin-top: 5px;
        }

        .login-form {
            padding: 30px;
        }

        .form-group {
            margin-bottom: 25px;
            position: relative;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #333;
            font-size: 14px;
        }

        .input-with-icon {
            position: relative;
        }

        .input-with-icon i {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: #1a3a6c;
            font-size: 18px;
        }

        .form-control {
            width: 100%;
            padding: 14px 14px 14px 45px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 16px;
            transition: all 0.3s ease;
        }

        .form-control:focus {
            border-color: #1a3a6c;
            box-shadow: 0 0 0 3px rgba(26, 58, 108, 0.1);
            outline: none;
        }

        .password-toggle {
            position: absolute;
            right: 15px;
            top: 50%;
            transform: translateY(-50%);
            background: none;
            border: none;
            color: #777;
            cursor: pointer;
            font-size: 18px;
        }

        .remember-forgot {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 25px;
            font-size: 14px;
        }

        .remember-me {
            display: flex;
            align-items: center;
        }

        .remember-me input {
            margin-right: 8px;
        }

        .forgot-password {
            color: #1a3a6c;
            text-decoration: none;
            font-weight: 600;
        }

        .forgot-password:hover {
            text-decoration: underline;
        }

        .btn-login {
            width: 100%;
            padding: 14px;
            background-color: #1a3a6c;
            color: white;
            border: none;
            border-radius: 6px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            letter-spacing: 1px;
            position: relative;
            overflow: hidden;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .btn-login:hover {
            background-color: #15315a;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(26, 58, 108, 0.3);
        }

        .btn-login::after {
            content: '';
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.2) 50%, rgba(255,255,255,0) 100%);
            transform: rotate(30deg);
            transition: all 0.6s ease;
        }

        .btn-login:hover::after {
            left: 100%;
        }

        .admin-warning {
            display: flex;
            align-items: center;
            background-color: #fff8e6;
            border-left: 4px solid #ffc107;
            padding: 12px 15px;
            margin-bottom: 20px;
            border-radius: 4px;
            font-size: 14px;
            animation: pulse 2s infinite;
        }

        .admin-warning i {
            color: #ffc107;
            font-size: 18px;
            margin-right: 10px;
        }

        .additional-options {
            margin-top: 25px;
            text-align: center;
            font-size: 14px;
        }

        .register-link {
            color: #1a3a6c;
            text-decoration: none;
            font-weight: 600;
            margin-left: 5px;
        }

        .register-link:hover {
            text-decoration: underline;
        }

        .footer {
            text-align: center;
            padding: 20px;
            color: #777;
            font-size: 12px;
            background-color: #f5f7fa;
            border-top: 1px solid #eee;
        }

        .admin-login-form {
            display: none;
        }

        .error-message {
            background-color: #ffebee;
            color: #c62828;
            padding: 10px 15px;
            border-radius: 4px;
            margin-bottom: 20px;
            display: flex;
            align-items: center;
            font-size: 14px;
            animation: fadeIn 0.3s ease-out;
        }

        .error-message i {
            margin-right: 10px;
        }

        .success-message {
            background-color: #e8f5e9;
            color: #2e7d32;
            padding: 10px 15px;
            border-radius: 4px;
            margin-bottom: 20px;
            display: flex;
            align-items: center;
            font-size: 14px;
            animation: fadeIn 0.3s ease-out;
        }

        .success-message i {
            margin-right: 10px;
        }

        .loading-spinner {
            border: 2px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top: 2px solid white;
            width: 16px;
            height: 16px;
            animation: spin 1s linear infinite;
            margin-right: 10px;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        @media (max-width: 480px) {
            body {
                padding: 10px;
            }

            .login-container {
                border-radius: 8px;
            }

            .login-header {
                padding: 20px;
            }

            .login-form {
                padding: 25px 20px;
            }

            .remember-forgot {
                flex-direction: column;
                align-items: flex-start;
                gap: 10px;
            }
        }

        /* 动画效果 */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @keyframes pulse {
            0% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.4); }
            70% { box-shadow: 0 0 0 10px rgba(255, 193, 7, 0); }
            100% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0); }
        }
    </style>
</head>
<body>

    <div class="login-container">
        <div class="login-header">
            <div class="login-tabs">
                <div class="tab active" data-type="customer">客户登录</div>
                <div class="tab" data-type="admin">管理员登录</div>
            </div>
            <h2 id="login-title">客户登录</h2>
            <p id="login-subtitle">安全访问您的银行账户</p>
        </div>

        <!-- 客户登录表单 -->
        <form class="login-form" id="customer-login-form">
            <div id="customer-login-message"></div>

            <div class="form-group">
                <label for="cardID">银行卡号</label>
                <div class="input-with-icon">
                    <i class="fas fa-credit-card"></i>
                    <input type="text" id="cardID" name="cardID" class="form-control" placeholder="请输入银行卡号" required>
                </div>
            </div>

            <div class="form-group">
                <label for="password">密码</label>
                <div class="input-with-icon">
                    <i class="fas fa-lock"></i>
                    <input type="password" id="password" name="password" class="form-control" placeholder="请输入密码" required>
                    <button type="button" class="password-toggle" id="togglePassword">
                        <i class="fas fa-eye"></i>
                    </button>
                </div>
            </div>

            <div class="remember-forgot">
                <div class="remember-me">
                    <input type="checkbox" id="remember" name="remember">
                    <label for="remember">记住我</label>
                </div>
                <a href="login/Reset Password.html" class="forgot-password">忘记密码?</a>
            </div>

            <button type="submit" class="btn-login" id="customer-login-btn">
                <span id="customer-login-text">登录系统</span>
                <div class="loading-spinner" id="customer-login-spinner" style="display: none;"></div>
            </button>
        </form>

        <!-- 管理员登录表单 -->
        <form class="login-form admin-login-form" id="admin-login-form">
            <div id="admin-login-message"></div>

            <div class="admin-warning">
                <i class="fas fa-exclamation-circle"></i>
                <span>管理员账户拥有高级权限，请谨慎操作</span>
            </div>

            <div class="form-group">
                <label for="admin-username">管理员ID</label>
                <div class="input-with-icon">
                    <i class="fas fa-user-shield"></i>
                    <input type="text" id="admin-username" name="admin_username" class="form-control" placeholder="输入管理员ID" required>
                </div>
            </div>

            <div class="form-group">
                <label for="admin-password">管理员密码</label>
                <div class="input-with-icon">
                    <i class="fas fa-lock"></i>
                    <input type="password" id="admin-password" name="admin_password" class="form-control" placeholder="输入管理员密码" required>
                    <button type="button" class="password-toggle" id="toggleAdminPassword">
                        <i class="fas fa-eye"></i>
                    </button>
                </div>
            </div>

            <div class="remember-forgot">
                <div class="remember-me">
                    <input type="checkbox" id="admin-remember" name="admin_remember">
                    <label for="admin-remember">信任此设备</label>
                </div>
            </div>

            <button type="submit" class="btn-login" id="admin-login-btn">
                <span id="admin-login-text">管理员登录</span>
                <div class="loading-spinner" id="admin-login-spinner" style="display: none;"></div>
            </button>
        </form>

        <div class="additional-options" id="customer-options">
            <span>还没有账户?</span>
            <a href="login/Register.html" class="register-link">立即注册</a>
        </div>

        <div class="additional-options admin-login-form" id="admin-options" style="display: none;">
            <span>管理员支持服务</span>
            <a href="mailto:3327187400@qq.com" class="register-link">联系系统管理员</a>
        </div>

        <div class="footer">
            <p>© 2025 银行业务系统 </p>
            <p>推荐使用最新版Chrome、Firefox或Edge浏览器</p>
            <p style="margin-top: 10px; font-size: 10px; color: #999;">
                <i class="fas fa-shield-alt"></i> 安全提醒：请勿在公共设备上保存登录信息
            </p>
        </div>
    </div>

    <script>
        // 密码显示/隐藏功能
        function setupPasswordToggle(passwordFieldId, toggleButtonId) {
            const passwordField = document.getElementById(passwordFieldId);
            const toggleButton = document.getElementById(toggleButtonId);

            if (passwordField && toggleButton) {
                toggleButton.addEventListener('click', function() {
                    const type = passwordField.getAttribute('type') === 'password' ? 'text' : 'password';
                    passwordField.setAttribute('type', type);

                    // 更新眼睛图标
                    const eyeIcon = toggleButton.querySelector('i');
                    if (type === 'password') {
                        eyeIcon.className = 'fas fa-eye';
                    } else {
                        eyeIcon.className = 'fas fa-eye-slash';
                    }
                });
            }
        }

        // 显示消息函数
        function showMessage(formId, message, isError = true) {
            const messageContainer = document.getElementById(`${formId}-message`);
            messageContainer.innerHTML = '';

            const messageDiv = document.createElement('div');
            messageDiv.className = isError ? 'error-message' : 'success-message';

            const icon = document.createElement('i');
            icon.className = isError ? 'fas fa-exclamation-triangle' : 'fas fa-check-circle';
            messageDiv.appendChild(icon);

            const text = document.createTextNode(message);
            messageDiv.appendChild(text);

            messageContainer.appendChild(messageDiv);

            // 自动消失（仅对成功消息）
            if (!isError) {
                setTimeout(() => {
                    messageDiv.style.opacity = '0';
                    setTimeout(() => {
                        messageContainer.removeChild(messageDiv);
                    }, 500);
                }, 3000);
            }
        }

        // 显示加载状态
        function showLoading(buttonId, spinnerId, textId) {
            const button = document.getElementById(buttonId);
            const spinner = document.getElementById(spinnerId);
            const text = document.getElementById(textId);

            button.disabled = true;
            text.style.opacity = '0.7';
            spinner.style.display = 'block';
        }

        // 隐藏加载状态
        function hideLoading(buttonId, spinnerId, textId) {
            const button = document.getElementById(buttonId);
            const spinner = document.getElementById(spinnerId);
            const text = document.getElementById(textId);

            button.disabled = false;
            text.style.opacity = '1';
            spinner.style.display = 'none';
        }

        // 初始化密码显示切换
        setupPasswordToggle('password', 'togglePassword');
        setupPasswordToggle('admin-password', 'toggleAdminPassword');

     // 客户登录表单处理
    document.getElementById('customer-login-form').addEventListener('submit', async function(e) {
        e.preventDefault();

        const cardID = document.getElementById('cardID').value;
        const password = document.getElementById('password').value;

        if (!cardID || !password) {
            showMessage('customer-login', '请输入银行卡号和密码');
            return;
        }

        // 显示加载状态
        showLoading('customer-login-btn', 'customer-login-spinner', 'customer-login-text');

        try {
            // 发送登录请求到API
            const response = await fetch('http://localhost:8080/customer/getBalance', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    cardID: cardID,
                    password: password
                })
            });

            // 解析响应数据
            const responseData = await response.json();

            // 判断响应体中的code字段
            if (responseData.code === 500) {
                // 服务器内部错误
                showMessage('customer-login',
                    `服务器错误: ${responseData.message || '请稍后再试'}`);
                return;
            }

            // 使用状态码判断
            if (responseData.code === '200') {
                // 登录成功
                showMessage('customer-login', '登录成功！正在跳转...', false);

                // 保存登录信息到sessionStorage
                sessionStorage.setItem('cardID', cardID);
                sessionStorage.setItem('userName', responseData.data.userName);
                sessionStorage.setItem('balance',  responseData.data.balance);

                // 3秒后跳转到用户页面
                setTimeout(() => {
                    window.location.href = 'user_home.html';
                }, 1500);
            }
            else if (response.status === 401 || responseData.code === 401) {
                // 未授权/密码错误
                showMessage('customer-login',
                    responseData.message || '银行卡号或密码错误');
            }
            else if (response.status === 400 || responseData.code === 400) {
                // 请求格式错误
                showMessage('customer-login',
                    responseData.message || '请求格式错误，请重试');
            }
            else if (response.status === 404 || responseData.code === 404) {
                // 用户不存在
                showMessage('customer-login',
                    responseData.message || '银行卡号不存在');
            }
            else {
                // 其他错误状态
                showMessage('customer-login',
                    `登录失败: ${responseData.message || '未知错误'}`);
            }
        } catch (error) {
            // 网络错误或JSON解析错误
            showMessage('customer-login', '无法连接到服务器，请检查网络连接');
            console.error('登录请求失败:', error);
        } finally {
            // 隐藏加载状态
            hideLoading('customer-login-btn', 'customer-login-spinner', 'customer-login-text');
        }
    });

        // 管理员登录表单处理
        document.getElementById('admin-login-form').addEventListener('submit', async function(e) {
            e.preventDefault();
            const username = document.getElementById('admin-username').value;
            const password = document.getElementById('admin-password').value;
            if (!username || !password) {
                showMessage('admin-login', '请输入管理员ID和密码');
                return;
            }
            showLoading('admin-login-btn', 'admin-login-spinner', 'admin-login-text');
            try {
                const response = await fetch('http://localhost:8080/admin/login', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                    body: `username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}`
                });
                const responseData = await response.json();
                if (responseData.code === '200') {
                    showMessage('admin-login', '管理员登录成功！正在跳转...', false);
                    sessionStorage.setItem('admin', JSON.stringify(responseData.data));
                    setTimeout(() => {
                        window.location.href = 'admin_home.html';
                    }, 1200);
                } else {
                    showMessage('admin-login', responseData.message || '管理员登录失败');
                }
            } catch (error) {
                showMessage('admin-login', '无法连接到服务器，请检查网络连接');
            } finally {
                hideLoading('admin-login-btn', 'admin-login-spinner', 'admin-login-text');
            }
        });

        // 选项卡切换功能
        const tabs = document.querySelectorAll('.tab');
        const customerForm = document.getElementById('customer-login-form');
        const adminForm = document.getElementById('admin-login-form');
        const customerOptions = document.getElementById('customer-options');
        const adminOptions = document.getElementById('admin-options');
        const loginTitle = document.getElementById('login-title');
        const loginSubtitle = document.getElementById('login-subtitle');

        tabs.forEach(tab => {
            tab.addEventListener('click', function() {
                // 更新选项卡状态
                tabs.forEach(t => t.classList.remove('active'));
                this.classList.add('active');

                const type = this.getAttribute('data-type');

                if (type === 'admin') {
                    // 切换到管理员登录
                    customerForm.style.display = 'none';
                    adminForm.style.display = 'block';
                    customerOptions.style.display = 'none';
                    adminOptions.style.display = 'block';
                    loginTitle.textContent = '管理员登录';
                    loginSubtitle.textContent = '银行管理系统安全访问';
                } else {
                    // 切换到客户登录
                    customerForm.style.display = 'block';
                    adminForm.style.display = 'none';
                    customerOptions.style.display = 'block';
                    adminOptions.style.display = 'none';
                    loginTitle.textContent = '客户登录';
                    loginSubtitle.textContent = '安全访问您的银行账户';
                }
            });
        });

        // 记住我功能
        document.getElementById('remember').addEventListener('change', function() {
            if (this.checked) {
                localStorage.setItem('rememberCardID', document.getElementById('cardID').value);
            } else {
                localStorage.removeItem('rememberCardID');
            }
        });

        // 页面加载时检查是否有保存的卡号
        window.addEventListener('DOMContentLoaded', function() {
            const savedCardID = localStorage.getItem('rememberCardID');
            if (savedCardID) {
                document.getElementById('cardID').value = savedCardID;
                document.getElementById('remember').checked = true;
            }
        });
    </script>
</body>
</html>